﻿using System;
using System.Data;
using System.Text;
using System.Data.SqlClient;
using Maticsoft.DBUtility;//Please add references
namespace JCNT.DAL.DB
{
	/// <summary>
	/// 数据访问类:wp_Note
	/// </summary>
	public partial class wp_Note
	{
		public wp_Note()
		{}
		#region  Method

		/// <summary>
		/// 得到最大ID
		/// </summary>
		public int GetMaxId()
		{
		return DbHelperSQL.GetMaxID("ID", "wp_Note"); 
		}

		/// <summary>
		/// 是否存在该记录
		/// </summary>
		public bool Exists(int ID)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("select count(1) from wp_Note");
			strSql.Append(" where ID=@ID ");
			SqlParameter[] parameters = {
					new SqlParameter("@ID", SqlDbType.Int,4)};
			parameters[0].Value = ID;

			return DbHelperSQL.Exists(strSql.ToString(),parameters);
		}


		/// <summary>
		/// 增加一条数据
		/// </summary>
		public bool Add(JCNT.Model.DB.wp_Note model)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("insert into wp_Note(");
			strSql.Append("ID,Tit,Con,Lab,SetDat,EdiDat,Oth,Pas1,pas2,pas3,pas4,RootID,Dat)");
			strSql.Append(" values (");
			strSql.Append("@ID,@Tit,@Con,@Lab,@SetDat,@EdiDat,@Oth,@Pas1,@pas2,@pas3,@pas4,@RootID,@Dat)");
			SqlParameter[] parameters = {
					new SqlParameter("@ID", SqlDbType.Int,4),
					new SqlParameter("@Tit", SqlDbType.NVarChar,50),
					new SqlParameter("@Con", SqlDbType.NText),
					new SqlParameter("@Lab", SqlDbType.NVarChar,50),
					new SqlParameter("@SetDat", SqlDbType.DateTime),
					new SqlParameter("@EdiDat", SqlDbType.DateTime),
					new SqlParameter("@Oth", SqlDbType.NVarChar,50),
					new SqlParameter("@Pas1", SqlDbType.NVarChar,50),
					new SqlParameter("@pas2", SqlDbType.NVarChar,50),
					new SqlParameter("@pas3", SqlDbType.NVarChar,50),
					new SqlParameter("@pas4", SqlDbType.NVarChar,50),
					new SqlParameter("@RootID", SqlDbType.Int,4),
					new SqlParameter("@Dat", SqlDbType.Image)};
			parameters[0].Value = model.ID;
			parameters[1].Value = model.Tit;
			parameters[2].Value = model.Con;
			parameters[3].Value = model.Lab;
			parameters[4].Value = model.SetDat;
			parameters[5].Value = model.EdiDat;
			parameters[6].Value = model.Oth;
			parameters[7].Value = model.Pas1;
			parameters[8].Value = model.pas2;
			parameters[9].Value = model.pas3;
			parameters[10].Value = model.pas4;
			parameters[11].Value = model.RootID;
			parameters[12].Value = model.Dat;

			int rows=DbHelperSQL.ExecuteSql(strSql.ToString(),parameters);
			if (rows > 0)
			{
				return true;
			}
			else
			{
				return false;
			}
		}
		/// <summary>
		/// 更新一条数据
		/// </summary>
		public bool Update(JCNT.Model.DB.wp_Note model)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("update wp_Note set ");
			strSql.Append("Tit=@Tit,");
			strSql.Append("Con=@Con,");
			strSql.Append("Lab=@Lab,");
			strSql.Append("SetDat=@SetDat,");
			strSql.Append("EdiDat=@EdiDat,");
			strSql.Append("Oth=@Oth,");
			strSql.Append("Pas1=@Pas1,");
			strSql.Append("pas2=@pas2,");
			strSql.Append("pas3=@pas3,");
			strSql.Append("pas4=@pas4,");
			strSql.Append("RootID=@RootID,");
			strSql.Append("Dat=@Dat");
			strSql.Append(" where ID=@ID ");
			SqlParameter[] parameters = {
					new SqlParameter("@Tit", SqlDbType.NVarChar,50),
					new SqlParameter("@Con", SqlDbType.NText),
					new SqlParameter("@Lab", SqlDbType.NVarChar,50),
					new SqlParameter("@SetDat", SqlDbType.DateTime),
					new SqlParameter("@EdiDat", SqlDbType.DateTime),
					new SqlParameter("@Oth", SqlDbType.NVarChar,50),
					new SqlParameter("@Pas1", SqlDbType.NVarChar,50),
					new SqlParameter("@pas2", SqlDbType.NVarChar,50),
					new SqlParameter("@pas3", SqlDbType.NVarChar,50),
					new SqlParameter("@pas4", SqlDbType.NVarChar,50),
					new SqlParameter("@RootID", SqlDbType.Int,4),
					new SqlParameter("@Dat", SqlDbType.Image),
					new SqlParameter("@ID", SqlDbType.Int,4)};
			parameters[0].Value = model.Tit;
			parameters[1].Value = model.Con;
			parameters[2].Value = model.Lab;
			parameters[3].Value = model.SetDat;
			parameters[4].Value = model.EdiDat;
			parameters[5].Value = model.Oth;
			parameters[6].Value = model.Pas1;
			parameters[7].Value = model.pas2;
			parameters[8].Value = model.pas3;
			parameters[9].Value = model.pas4;
			parameters[10].Value = model.RootID;
			parameters[11].Value = model.Dat;
			parameters[12].Value = model.ID;

			int rows=DbHelperSQL.ExecuteSql(strSql.ToString(),parameters);
			if (rows > 0)
			{
				return true;
			}
			else
			{
				return false;
			}
		}

		/// <summary>
		/// 删除一条数据
		/// </summary>
		public bool Delete(int ID)
		{
			
			StringBuilder strSql=new StringBuilder();
			strSql.Append("delete from wp_Note ");
			strSql.Append(" where ID=@ID ");
			SqlParameter[] parameters = {
					new SqlParameter("@ID", SqlDbType.Int,4)};
			parameters[0].Value = ID;

			int rows=DbHelperSQL.ExecuteSql(strSql.ToString(),parameters);
			if (rows > 0)
			{
				return true;
			}
			else
			{
				return false;
			}
		}
		/// <summary>
		/// 批量删除数据
		/// </summary>
		public bool DeleteList(string IDlist )
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("delete from wp_Note ");
			strSql.Append(" where ID in ("+IDlist + ")  ");
			int rows=DbHelperSQL.ExecuteSql(strSql.ToString());
			if (rows > 0)
			{
				return true;
			}
			else
			{
				return false;
			}
		}


		/// <summary>
		/// 得到一个对象实体
		/// </summary>
		public JCNT.Model.DB.wp_Note GetModel(int ID)
		{
			
			StringBuilder strSql=new StringBuilder();
			strSql.Append("select  top 1 ID,Tit,Con,Lab,SetDat,EdiDat,Oth,Pas1,pas2,pas3,pas4,RootID,Dat from wp_Note ");
			strSql.Append(" where ID=@ID ");
			SqlParameter[] parameters = {
					new SqlParameter("@ID", SqlDbType.Int,4)};
			parameters[0].Value = ID;

			JCNT.Model.DB.wp_Note model=new JCNT.Model.DB.wp_Note();
			DataSet ds=DbHelperSQL.Query(strSql.ToString(),parameters);
			if(ds.Tables[0].Rows.Count>0)
			{
				if(ds.Tables[0].Rows[0]["ID"]!=null && ds.Tables[0].Rows[0]["ID"].ToString()!="")
				{
					model.ID=int.Parse(ds.Tables[0].Rows[0]["ID"].ToString());
				}
				if(ds.Tables[0].Rows[0]["Tit"]!=null && ds.Tables[0].Rows[0]["Tit"].ToString()!="")
				{
					model.Tit=ds.Tables[0].Rows[0]["Tit"].ToString();
				}
				if(ds.Tables[0].Rows[0]["Con"]!=null && ds.Tables[0].Rows[0]["Con"].ToString()!="")
				{
					model.Con=ds.Tables[0].Rows[0]["Con"].ToString();
				}
				if(ds.Tables[0].Rows[0]["Lab"]!=null && ds.Tables[0].Rows[0]["Lab"].ToString()!="")
				{
					model.Lab=ds.Tables[0].Rows[0]["Lab"].ToString();
				}
				if(ds.Tables[0].Rows[0]["SetDat"]!=null && ds.Tables[0].Rows[0]["SetDat"].ToString()!="")
				{
					model.SetDat=DateTime.Parse(ds.Tables[0].Rows[0]["SetDat"].ToString());
				}
				if(ds.Tables[0].Rows[0]["EdiDat"]!=null && ds.Tables[0].Rows[0]["EdiDat"].ToString()!="")
				{
					model.EdiDat=DateTime.Parse(ds.Tables[0].Rows[0]["EdiDat"].ToString());
				}
				if(ds.Tables[0].Rows[0]["Oth"]!=null && ds.Tables[0].Rows[0]["Oth"].ToString()!="")
				{
					model.Oth=ds.Tables[0].Rows[0]["Oth"].ToString();
				}
				if(ds.Tables[0].Rows[0]["Pas1"]!=null && ds.Tables[0].Rows[0]["Pas1"].ToString()!="")
				{
					model.Pas1=ds.Tables[0].Rows[0]["Pas1"].ToString();
				}
				if(ds.Tables[0].Rows[0]["pas2"]!=null && ds.Tables[0].Rows[0]["pas2"].ToString()!="")
				{
					model.pas2=ds.Tables[0].Rows[0]["pas2"].ToString();
				}
				if(ds.Tables[0].Rows[0]["pas3"]!=null && ds.Tables[0].Rows[0]["pas3"].ToString()!="")
				{
					model.pas3=ds.Tables[0].Rows[0]["pas3"].ToString();
				}
				if(ds.Tables[0].Rows[0]["pas4"]!=null && ds.Tables[0].Rows[0]["pas4"].ToString()!="")
				{
					model.pas4=ds.Tables[0].Rows[0]["pas4"].ToString();
				}
				if(ds.Tables[0].Rows[0]["RootID"]!=null && ds.Tables[0].Rows[0]["RootID"].ToString()!="")
				{
					model.RootID=int.Parse(ds.Tables[0].Rows[0]["RootID"].ToString());
				}
				if(ds.Tables[0].Rows[0]["Dat"]!=null && ds.Tables[0].Rows[0]["Dat"].ToString()!="")
				{
					model.Dat=(byte[])ds.Tables[0].Rows[0]["Dat"];
				}
				return model;
			}
			else
			{
				return null;
			}
		}

		/// <summary>
		/// 获得数据列表
		/// </summary>
		public DataSet GetList(string strWhere)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("select ID,Tit,Con,Lab,SetDat,EdiDat,Oth,Pas1,pas2,pas3,pas4,RootID,Dat ");
			strSql.Append(" FROM wp_Note ");
			if(strWhere.Trim()!="")
			{
				strSql.Append(" where "+strWhere);
			}
			return DbHelperSQL.Query(strSql.ToString());
		}

		/// <summary>
		/// 获得前几行数据
		/// </summary>
		public DataSet GetList(int Top,string strWhere,string filedOrder)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("select ");
			if(Top>0)
			{
				strSql.Append(" top "+Top.ToString());
			}
			strSql.Append(" ID,Tit,Con,Lab,SetDat,EdiDat,Oth,Pas1,pas2,pas3,pas4,RootID,Dat ");
			strSql.Append(" FROM wp_Note ");
			if(strWhere.Trim()!="")
			{
				strSql.Append(" where "+strWhere);
			}
			strSql.Append(" order by " + filedOrder);
			return DbHelperSQL.Query(strSql.ToString());
		}

		/*
		/// <summary>
		/// 分页获取数据列表
		/// </summary>
		public DataSet GetList(int PageSize,int PageIndex,string strWhere)
		{
			SqlParameter[] parameters = {
					new SqlParameter("@tblName", SqlDbType.VarChar, 255),
					new SqlParameter("@fldName", SqlDbType.VarChar, 255),
					new SqlParameter("@PageSize", SqlDbType.Int),
					new SqlParameter("@PageIndex", SqlDbType.Int),
					new SqlParameter("@IsReCount", SqlDbType.Bit),
					new SqlParameter("@OrderType", SqlDbType.Bit),
					new SqlParameter("@strWhere", SqlDbType.VarChar,1000),
					};
			parameters[0].Value = "wp_Note";
			parameters[1].Value = "ID";
			parameters[2].Value = PageSize;
			parameters[3].Value = PageIndex;
			parameters[4].Value = 0;
			parameters[5].Value = 0;
			parameters[6].Value = strWhere;	
			return DbHelperSQL.RunProcedure("UP_GetRecordByPage",parameters,"ds");
		}*/

		#endregion  Method
	}
}

